

<template>
   <div class="my-80">
    <div class="m-[10px] w-[100vw] flex flex-col gap-[10px]">
        <div name="图片" class="flex flex-col w-[100%] h-[100%] bg-white relative p-10">
            <EImageList v-model:photoList="testObj.product.photoList" />
        </div>
      <van-field @blur="()=>{
        console.log(testObj.product.badQuantity);
        testObj.product.badQuantity = testObj.product.quantity - testObj.product.goodQuantity
        console.log('新'+testObj.product.badQuantity);
      }" class="rounded-[10px] h-[60px] flex items-center"
      label="良品数量" v-model="testObj.product.goodQuantity" type="digit" placeholder="请输入" />
      <van-field @blur="()=>{
        testObj.product.goodQuantity = testObj.product.quantity - testObj.product.badQuantity
        console.log('新'+testObj.product.goodQuantity);
      }" class="rounded-[10px] h-[60px] flex items-center" v-model="testObj.product.badQuantity" type="digit"  label="不良品数量" />

<van-field
    v-model="testObj.product.testFunc"
    rows="2"
    autosize
    label="测试方法"
    type="textarea"
    maxlength="50"
    placeholder="请输入测试方法"
    show-word-limit
  />
  <van-field
    v-model="testObj.product.remark"
    rows="2"
    autosize
    label="备注"
    type="textarea"
    maxlength="50"
    placeholder="请输入备注"
    show-word-limit
  />
      <StepBottom v-model="inputData">
          <template #default>
            <div>
              <span class="step-bottom-h2" @click="() => {
               onBack()
              }">取消</span>
            </div>
            <el-button class="step-bottom-button flex flex-col justify-center items-center text-white"
                       @click="registerTest">提交测试结果
            </el-button>
          </template>
      </StepBottom>
    </div>

   </div>
</template>
<script setup>
import {showConfirmDialog} from "vant";
import {RegisterTestResult} from "@/api/Base/preTest.ts";

let preNo = ref("");

definePage({
  name: 'registerTest',
  meta: {
    level: 2,
    title: '测试',
  },
})
const load = ref(false)

const testObj = reactive({
  product: {
    photoList: [],
    quantity: 10,
    badQuantity: 0,
    goodQuantity: 10,
    testFunc: "",
    remark: ""
  },
  reload: () => {
    // queryPreregisterApp({
    //   page: 1,
    //   pageSize: 999999,
    //   startTime: arriveObj.search.startTime,
    //   endTime: arriveObj.search.endTime,
    //   keyword: arriveObj.search.searchText,
    //   status: arriveObj.search.active
    // }).then(res => {
    //   if (res.code == 0) {
    //     arriveObj.list = res.data.list
    //   }
    // })
  }
})

const router = useRouter()

/**
 * 登记测试数据
 */
function registerTest() {
  RegisterTestResult({
    "preRegisterNo": preNo.value,
    "testMethod": testObj.product.testFunc,
    "testFileUrls": testObj.product.photoList,
    "description": testObj.product.remark,
    "goodNumber": testObj.product.goodQuantity,
    "badNumber": testObj.product.badQuantity
  }).then(d => {
    console.log(d);

    if (d.code == 0) {
      showConfirmDialog({
        title: "登记测试信息成功",
        message: "已经登记成功,是否继续修改测试结果?"
      }).then(() => {
        
      }).catch(() => {
        router.replace("/")

      })
    }

  })
}


function onBack() {
  if (window.history.state.back)
    history.back()
  else
    router.replace('/')
}

onMounted(() => {
  //安全检查
  if (route.query.id == undefined || route.query.id == null) {
    showConfirmDialog({
      message: "获取预登记号失败!"
    });
    router.replace("/")
    return;
  }
  preNo.value = route.query.id;


})
const route = useRoute()
</script>
<style lang="less" scoped>
.search {
  // width: 110px;
  height: 2rem;
  border-radius: 5px;
  opacity: 1;

  /* 纯白 */
  background: #FFFFFF;

}
</style>
